package com.example.springbootdemo.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.util.StringUtils;

import java.io.IOException;

public class ImageUrlSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
        String resourceDomain = "https://ts4.cn.mm.bing.net";
        gen.writeString(!StringUtils.hasText(value) ? "" : resourceDomain.concat(value));
    }

}
